unit _data;
interface
uses StdCtrls, dialogs;

  Type TLogLevel = (llDebug, llInfo, llError);
  Type TAppLog = class
    constructor Create(var logWindow:TMemo);
    procedure error(message:string);
    procedure info(message:string);
    procedure debug(message:string);
    procedure write(message:string);
    procedure setLoggingLevel(const level:TLogLevel);
    function getLoggingLevel:TLogLevel;
    private
      _log:TMemo;
      _logLevel:TLogLevel;
  end;

var log:TAppLog;

implementation

constructor TAppLog.Create(var logWindow:TMemo);
begin
  _log := logWindow;
  _logLevel := llInfo;
end;

procedure TAppLog.write(message:string);
begin
  _log.lines.add(message);
end;

procedure TAppLog.error(message:string);
begin
  if (_logLevel <= llError) then self.write('ERROR: ' + message);
end;

procedure TAppLog.info(message:string);
begin
  if (ord(_logLevel) <= ord(llInfo)) then self.write(' INFO: ' + message);
end;

procedure TAppLog.debug(message:string);
begin
  if (_logLevel <= llDebug) then self.write('DEBUG: ' + message);
end;

procedure TAppLog.setLoggingLevel(const level:TLogLevel);
begin
  self._logLevel := level;
end;

function TAppLog.getLoggingLevel:TLogLevel;
begin
  result := _logLevel;
end;


end.
